#!/usr/bin/python

import os,sys
from PyQt4 import QtGui, QtCore

class MainWindow(QtGui.QMainWindow):
    def __init__(self, parent=None):
        QtGui.QMainWindow.__init__(self)
        
        self.resize(640, 480)
        self.setWindowTitle('light todo')

        sansFont = QtGui.QFont("Sans", 8)
        self.setFont(sansFont)

        # toolbar

        self.autosave = QtGui.QAction(QtGui.QIcon('icons/save.png'), 'Toggle autosave', self)
        self.autosave.setShortcut('Ctrl+Q')
        self.connect(self.autosave, QtCore.SIGNAL('triggered()'), self.toggleAutosave)

        self.exit = QtGui.QAction(QtGui.QIcon('icons/close.png'), 'Exit', self)
        self.exit.setShortcut('Ctrl+Q')
        self.connect(self.exit, QtCore.SIGNAL('triggered()'), QtCore.SLOT('close()'))

        self.toolbar = self.addToolBar('common')
        self.toolbar.addAction(self.autosave)
        self.toolbar.addAction(self.exit)

        # todo list and command line

        todoWidgetLabel = QtGui.QLabel("Review and dive into your remaining todos.")
        todoWidget = QtGui.QTreeWidget();
        commandWidgetLabel = QtGui.QLabel("Command line, the central place to "
            + "alter your todo list items as well as to create new ones.")
        commandWidget = QtGui.QPlainTextEdit()

        # dummy widget to contain the layout manager

        self.mainWidget = QtGui.QWidget(self) 
        self.setCentralWidget(self.mainWidget)

        vbox = QtGui.QVBoxLayout(self.mainWidget)
        vbox.addWidget(todoWidgetLabel)
        vbox.addWidget(todoWidget)
        vbox.addWidget(commandWidgetLabel)
        vbox.addWidget(commandWidget)

        # set properties

        QtGui.QPlainTextEdit.centerOnScroll(commandWidget)

        # some basic test initializations

        todoHeaders = ['ID', 'Priority', 'Title', 'Contexts']
        todoWidget.setColumnCount(4)
        todoWidget.setHeaderLabels(todoHeaders)
        todoWidget.setColumnWidth(0, 40)
        todoWidget.setColumnWidth(1, 60)
        todoWidget.setColumnWidth(2, 375)

        sampleItem = QtGui.QTreeWidgetItem(todoWidget)
        # sampleItem.setFlags(Qt.ItemIsEnabled | Qt.ItemIsEditable | Qt.ItemIsUserCheckable)
        sampleItem.setCheckState(0, QtCore.Qt.Unchecked)
        sampleItem.setText(0, "1")
        sampleItem.setText(1, "4/5")
        sampleItem.setText(2, "Finish the interface (gui) design of light-todo")
        sampleItem.setText(3, "todo title")

    def toggleAutosave(self,checked=None):
        if checked is None: return

app = QtGui.QApplication(sys.argv)
main = MainWindow()
main.show()
sys.exit(app.exec_())
